As increasing amounts of information are stored, exchanged, and presented employing a node-based language such as XML, for example, the ability to intelligently query such data sources becomes progressively more important. For instance, one of the great strengths of XML is its flexibility in representing many different types of information from diverse sources. To exploit this flexibility, an XML programming language should at a minimum provide features for querying, retrieving, and interpreting information from these diverse sources.
A standard mechanism for querying XML documents employs the XPath language. However, XPath, as defined by the W3C XML Query Working Group, lacks a number of critical concepts required for practical application. For instance, XPath lacks the ability to filter data at a desired level of granularity, to easily re-shape the data, to sort the data, and to extend the data with computed nodes. XML Query (XQuery), attempts to address a number of these issues but imposes a heavy burden on the query developer and in many cases still suffers from some of the data manipulation shortcomings in XPath.
With respect to XQuery, it is designed to perform as a language in which queries are concise and easily understood. It is also flexible enough to query a broad spectrum of XML information sources, including both databases and documents. The Query Working Group has identified a requirement for both non-XML query syntax and XML-based query syntax, whereby XQuery is designed to meet the first of these requirements. In general, XQuery is derived from an XML language referred to as “Quilt”, which in turn borrowed features from several other languages, including XPath, XQL, XML-QL, SQL, and OQL, for example.
The basic building block of XQuery is an expression, which is a string of characters. The language provides several types of expressions which may be constructed from keywords, symbols, and operands. In general, the operands of an expression are other expressions. Thus, XQuery is considered a functional language, which implies that expressions can be nested with full generality. However, unlike a pure functional language, it does not allow variable substitutability if the variable declaration contains construction of new nodes. Also, XQuery is a strongly-typed language in which the operands of various expressions, operators, and functions conform to the expected types.